package jsp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:石小俊
 * @Date:2022/12/13 9:04
 * @Version:1.0-SNAPSHOT
 * @Description:
 */
@WebServlet("/show/*")
public class ShowServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        request.getRequestDispatcher("/WEB-INF/test.jsp").forward(request,response);
        // /WEB-INF		/test					.jsp
        // /WEB-INF		/pages/test01			.jsp
        // /WEB-INF		/pages/test02			.jsp
        // /WEB-INF		/pages/backend/login	.jsp
        // /show/test --> /WEB-INF/test.jsp
        // /show/pages/test01 --> /WEB-INF/pages/test01.jsp
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri);

        String contextPath = request.getContextPath();
        System.out.println("contextPath:"+contextPath);

        String servletPath = request.getServletPath();
        System.out.println("servletPath:"+servletPath);

        String path = uri.substring((contextPath+servletPath).length());
        System.out.println("path:"+path);

        request.getRequestDispatcher("/WEB-INF"+path+".jsp").forward(request,response);
    }

}
